//
//  MyCollectionOfDestinationViewController.m
//  FreeTravel
//
//  Created by 徐康 on 16/9/18.
//  Copyright © 2016年 KX. All rights reserved.
//
#import "WebViewOfCommendViewController.h"
#import "MyCollectionOfDestinationViewController.h"
#import "FreeTravelMacro.h"
#import "CellOfHotCommunity.h"
#import "FreeTravelNetwork.h"
#import "ModelOfHotCommunityData.h"
#import "ModelOfHotCommunity.h"
#import "TextAdaptation.h"
#import <UIKit/UIKit.h>
@interface MyCollectionOfDestinationViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) ModelOfHotCommunity *model;
@end

@implementation MyCollectionOfDestinationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.title = @"我收藏的帖子";
    [self handleData];
    [self createTableView];
}
- (void)handleData{
    [FreeTravelNetwork GET:[NSString stringWithFormat:@"http://open.qyer.com/qyer/bbs/thread_list?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=10&oauth_token=28917df66c628f58bfe28ef6a6a297ef&page=1&track_app_channel=App%%2520Store&track_app_version=7.0.1&track_device_info=iPhone%%25205s&track_deviceid=E9CA001A-5603-4CA8-B2EA-2BE34F691AC6&track_os=ios%%25209.3.5&track_user_id=8333160&type=fav&user_id=%@&v=1",self.userID] andBody:nil andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
                self.model = [ModelOfHotCommunity modelWithDic:result];
        NSLog(@"%@",self.model);
        [self.tableView reloadData];
    } andFailureBlock:^(NSError *error) {
        
    }];
}
- (void)createTableView{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-108) style:UITableViewStylePlain];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[CellOfHotCommunity class] forCellReuseIdentifier:@"MyCollectionOfDestinationViewControllerCell"];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.model.data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CellOfHotCommunity *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCollectionOfDestinationViewControllerCell"];
    cell.model = self.model.data[indexPath.row];
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    ModelOfHotCommunityData *model = self.model.data[indexPath.row];
    CGSize size = [TextAdaptation labelRectWithSize:CGSizeMake(SCREEN_WIDTH-60, CGFLOAT_MAX) LabelText:model.title Font:[UIFont systemFontOfSize:15]];
    if (model.bigpic_arr.count>0) {
        return size.height+90+(SCREEN_WIDTH-80)/3;
    }else{
        return size.height+90;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    WebViewOfCommendViewController *vc = [[WebViewOfCommendViewController alloc]init];
    ModelOfHotCommunityData *model = self.model.data[indexPath.row];
    vc.url = model.view_url;
    
    [self.navigationController pushViewController:vc animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
